package com.lezijie.seckill.controller;

import com.lezijie.seckill.service.IUserService;
import com.lezijie.seckill.vo.LoginVO;
import com.lezijie.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * Login前端控制器
 * @author SunZhiPeng
 * @createDate 2021-10-21 16:48
 */
@Slf4j
@Controller
@RequestMapping("/login")
public class LoginController {

    @Resource
    private IUserService userService;

    /**
     * 登录页面
     * @return 返回login.html页面（登录页面）
     */
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    /**
     * 登录功能
     * @param loginVO 登录参数
     * @return RespBean对象，登录成功或者失败参数
     */
    @PostMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVO loginVO, HttpServletRequest request, HttpServletResponse response) {
        log.info("传输过来的值是：" + loginVO);
        return userService.doLogin(loginVO,request,response);
    }

}
